unit EnhancedLogger;

interface

uses
  System.SysUtils, System.Classes, System.Generics.Collections, System.SyncObjs,
  Sparkle.Logger;

type
  TLogLevel = (llDebug, llInfo, llWarning, llError, llFatal);

  IEnhancedLogEngine = interface
    ['{A3B8C7D9-4E5F-4A2B-8C1D-9E6F5A3B7C8E}']
    procedure Debug(const Msg: string);
    procedure Info(const Msg: string);
    procedure Warning(const Msg: string);
    procedure Error(const Msg: string);
    procedure Fatal(const Msg: string);
    procedure Log(const Msg: string; Level: TLogLevel);
  end;

  TEnhancedLogger = class(TInterfacedObject, IEnhancedLogEngine)
  private
    FLogEngine: ILogEngine;
    function GetLevelPrefix(Level: TLogLevel): string;
  public
    constructor Create(ALogEngine: ILogEngine);

    procedure Debug(const Msg: string);
    procedure Info(const Msg: string);
    procedure Warning(const Msg: string);
    procedure Error(const Msg: string);
    procedure Fatal(const Msg: string);
    procedure Log(const Msg: string; Level: TLogLevel);
  end;

implementation

{ TEnhancedLogger }

constructor TEnhancedLogger.Create(ALogEngine: ILogEngine);
begin
  inherited Create;
  FLogEngine := ALogEngine;
end;

function TEnhancedLogger.GetLevelPrefix(Level: TLogLevel): string;
const
  LevelPrefix: array[TLogLevel] of string = ('[DEBUG]', '[INFO]', '[WARNING]', '[ERROR]', '[FATAL]');
begin
  Result := LevelPrefix[Level];
end;

procedure TEnhancedLogger.Debug(const Msg: string);
begin
  Log(Msg, llDebug);
end;

procedure TEnhancedLogger.Info(const Msg: string);
begin
  Log(Msg, llInfo);
end;

procedure TEnhancedLogger.Warning(const Msg: string);
begin
  Log(Msg, llWarning);
end;

procedure TEnhancedLogger.Error(const Msg: string);
begin
  Log(Msg, llError);
end;

procedure TEnhancedLogger.Fatal(const Msg: string);
begin
  Log(Msg, llFatal);
end;

procedure TEnhancedLogger.Log(const Msg: string; Level: TLogLevel);
var
  LogMsg: string;
begin
  LogMsg := Format('%s %s', [GetLevelPrefix(Level), Msg]);
  FLogEngine.Log(LogMsg);
end;

end.
